Skip to content

Conversation

LiarPrincess
Copy link

Please read the #242 Using tests from “Violet - Python VM written in Swift” before.


❌ Failures

func test_binarySub() {
  // https://www.wolframalpha.com/input?i=-922337203685477587+-+%28-9223372036854775808%29
  let lhs = BigInt("-922337203685477587")!
  let rhs = BigInt("-9223372036854775808")!
  let expected = BigInt("8301034833169298221")!
  XCTAssertEqual(lhs - rhs, expected)
  // The same on Swift.Int:
  XCTAssertEqual(-922337203685477587 - (-9223372036854775808), 8301034833169298221)
}

func test_binarySub_2() {
  typealias Word = BigIntPrototype.Word

  let intMax = Int.max
  let intMaxAsWord = Word(intMax.magnitude)

  // intMax - (-(Word.max - intMaxAsWord)) =
  // intMax - (-Word.max + intMaxAsWord) =
  // intMax + Word.max - intMaxAsWord =
  // Word.max
  let max = BigInt(intMax)
  let value = BigInt(.negative, magnitude: Word.max - intMaxAsWord)
  let expected = BigInt(.positive, magnitude: Word.max)
  XCTAssertEqual(max - value, expected)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant